




/*
'===============================================================================
'  HNG.Portal.BL.TblStatsTypeManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblStatsTypeManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_Name="Name";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblStatsTypeManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_Name,typeof(string));
			
			            
            return dt;			
		}
			
		public TblStatsTypeEntity Convert_Entity(TblStatsTypeEntity _TblStatsTypeEntity,TblStatsTypeEntity _TblStatsTypeEntity_XML)
		{	
			
				
			_TblStatsTypeEntity.Id= _TblStatsTypeEntity_XML.Id;
				
			_TblStatsTypeEntity.Name= _TblStatsTypeEntity_XML.Name;
				
			
			return _TblStatsTypeEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblStatsTypeEntity Insert(TblStatsTypeEntity TblStatsTypeEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblStatsTypeEntity, true);
			}
			return TblStatsTypeEntity;
		}

		
		public TblStatsTypeEntity Insert(int Id, string Name)
		{
			TblStatsTypeEntity _TblStatsTypeEntity = new TblStatsTypeEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblStatsTypeEntity.Id = Id;
				_TblStatsTypeEntity.Name = Name;
				adapter.SaveEntity(_TblStatsTypeEntity, true);
			}
			return _TblStatsTypeEntity;
		}

		public TblStatsTypeEntity Insert(string Name)
		{
			TblStatsTypeEntity _TblStatsTypeEntity = new TblStatsTypeEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblStatsTypeEntity.Name = Name;
				adapter.SaveEntity(_TblStatsTypeEntity, true);
			}
			return _TblStatsTypeEntity;
		}

		public bool Update(TblStatsTypeEntity _TblStatsTypeEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblStatsTypeFields.Id == _TblStatsTypeEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblStatsTypeEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblStatsTypeEntity _TblStatsTypeEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblStatsTypeEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, string Name)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblStatsTypeEntity _TblStatsTypeEntity = new TblStatsTypeEntity(Id);
				if (adapter.FetchEntity(_TblStatsTypeEntity))
				{
				
					_TblStatsTypeEntity.Name = Name;
					adapter.SaveEntity(_TblStatsTypeEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblStatsTypeEntity _TblStatsTypeEntity = new TblStatsTypeEntity(Id);
				if (adapter.FetchEntity(_TblStatsTypeEntity))
				{
					adapter.DeleteEntity(_TblStatsTypeEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblStatsTypeEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsTypeFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblStatsTypeEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByName(string Name)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsTypeFields.Name == Name);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblStatsTypeEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblStatsTypeEntity SelectOne(int Id)
		{
			TblStatsTypeEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblStatsTypeEntity _TblStatsTypeEntity = new TblStatsTypeEntity(Id);
				if (adapter.FetchEntity(_TblStatsTypeEntity))
				{
					toReturn = _TblStatsTypeEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblStatsTypeCollection = new EntityCollection( new TblStatsTypeEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsTypeCollection, null, 0, null);
			}
			return _TblStatsTypeCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsTypeCollection = new EntityCollection(new TblStatsTypeEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsTypeCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblStatsTypeCollection = new EntityCollection(new TblStatsTypeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsTypeFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsTypeCollection, filter, 0, null);
			}
			return _TblStatsTypeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsTypeCollection = new EntityCollection(new TblStatsTypeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsTypeFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsTypeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByName(string Name)
		{
			EntityCollection _TblStatsTypeCollection = new EntityCollection(new TblStatsTypeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsTypeFields.Name == Name);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsTypeCollection, filter, 0, null);
			}
			return _TblStatsTypeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByNameRDT(string Name)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsTypeCollection = new EntityCollection(new TblStatsTypeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsTypeFields.Name == Name);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsTypeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
